﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace PFAGame
{
    class Bishop : AMob
    {
        static SoundEffect sound;
        SoundEffectInstance soundInstance;

        bool playInit = false;
        bool asPlayedInit = false;
        float timebeforePlay = 0.3f;
        bool asPlayedDead = false;

        public Bishop(float x, float y)
        {
            position.X = x;
            position.Y = y;
            type = e_typeMob.BISHOP;

            moveRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenRunSide"), 503, 504, 2, (int)(100 / speed), true);
            moveLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenRunSide2"), 503, 504, 2, (int)(100 / speed), true);
            moveUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenRunFront"), 503, 504, 2, (int)(100 / speed), true);
            moveDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenRunBack"), 503, 504, 2, (int)(100 / speed), true);

            attackRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenHitSide"), 503, 504, 3, (int)(30 * speed), false);
            attackLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenHitSide2"), 503, 504, 3, (int)(30 * speed), false);
            attackUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenHitFront"), 503, 504, 3, (int)(30 * speed), false);
            attackDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MadMen/MadMenHitBack"), 503, 504, 3, (int)(30 * speed), false);

            color = Color.White;
            scale = 3.0f;
            radius = 1.1f;

            if (sound == null)
                sound = ScreenManager.Singleton.Game.Content.Load<SoundEffect>("Sound_effects/swort_hit");
            soundInstance = sound.CreateInstance();
            soundInstance.Volume = 0.2f;
            soundInstance.IsLooped = false;
        }

        public override void update(GameTime gameTime)
        {
            e_state lastState = state;
            base.update(gameTime);

            // son init
            if (playInit)
            {
                timebeforePlay -= (float)gameTime.ElapsedGameTime.Ticks / 10000000;
                if (timebeforePlay < 0)
                {
                    playInit = false;
                    SoundManager.Singleton.PlayVoice(3);
                }
            }

            //son mort
            if (state == e_state.DYING && !asPlayedDead)
            {
                SoundManager.Singleton.PlayVoice(4);
                asPlayedDead = true;
            }
        }

        public override void draw(GameTime gameTime, Camera camera)
        {
            // lance le son dés que le mob est viisible
            if (!asPlayedInit && camera.isInFrustum(position))
            {
                asPlayedInit = true;
                playInit = true;
            }

            base.draw(gameTime, camera);
        }

        protected override void attack()
        {
            //inflige les dégats, si la cibles est toujours à porté
            if (target.getSquaredDistance(position) <= range * range)
                target.receiveDammage(dammage);

            sound.Play();
        }

        public override void init()
        {
            base.init();
            life = 800;
            exp = 80;
            speed = 2.6f;
        }
    }
}
